package com.ruoyi.fsepc.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.fsepc.domain.FseStAppVersion;
import com.ruoyi.fsepc.service.IFseStAppVersionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * APP版本管理Controller
 * 
 * @author ruoyi
 * @date 2020-04-21
 */
@Controller
@RequestMapping("/fsepc/version")
public class FseStAppVersionController extends BaseController
{
    private String prefix = "fsepc/appVersion";

    @Autowired
    private IFseStAppVersionService fseStAppVersionService;

    /**
     * app版本管理
     *
     * @author qinheyang
     * @date 2020-04-21
     */
    @RequiresPermissions("fsepc:version:view")
    @GetMapping()
    public String version()
    {
        return prefix + "/version";
    }


    /**
     * 查看服务条款详情
     *
     * @author qinheyang
     * @date 2020-04-21
     */
    @GetMapping("/versionDetail")
    public String vsersionDetail(Long id,ModelMap mmap){
        FseStAppVersion fseStAppVersion = fseStAppVersionService.selectFseStAppVersionById(id);
        mmap.put( "fseStAppVersion",fseStAppVersion);
        return prefix+"/versionDetail";
    }
    /**
     * 依据版本号查询 判断添加或修改的版本号是否存在
     *
     * @author qinheyang
     * @date 2020-04-21
     */
    @PostMapping ("/selectByVersionCode")
    @ResponseBody
    public List<FseStAppVersion> selectByVersionCode(FseStAppVersion fseStAppVersion){
        return fseStAppVersionService.selectFseStAppVersionList(fseStAppVersion);
    }



    /**
     * 查询APP版本管理列表
     */
    @RequiresPermissions("fsepc:version:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FseStAppVersion fseStAppVersion)
    {
        startPage();
        List<FseStAppVersion> list = fseStAppVersionService.selectFseStAppVersionList(fseStAppVersion);
        return getDataTable(list);
    }

    /**
     * 导出APP版本管理列表
     */
    @RequiresPermissions("fsepc:version:export")
    @Log(title = "APP版本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FseStAppVersion fseStAppVersion)
    {
        List<FseStAppVersion> list = fseStAppVersionService.selectFseStAppVersionList(fseStAppVersion);
        ExcelUtil<FseStAppVersion> util = new ExcelUtil<FseStAppVersion>(FseStAppVersion.class);
        return util.exportExcel(list, "version");
    }

    /**
     * 新增APP版本管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存APP版本管理
     */
    @RequiresPermissions("fsepc:version:add")
    @Log(title = "APP版本管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FseStAppVersion fseStAppVersion)
    {
        return toAjax(fseStAppVersionService.insertFseStAppVersion(fseStAppVersion));
    }

    /**
     * 修改APP版本管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FseStAppVersion fseStAppVersion = fseStAppVersionService.selectFseStAppVersionById(id);
        mmap.put("fseStAppVersion", fseStAppVersion);
        return prefix + "/edit";
    }

    /**
     * 修改保存APP版本管理
     */
    @RequiresPermissions("fsepc:version:edit")
    @Log(title = "APP版本管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FseStAppVersion fseStAppVersion)
    {
        return toAjax(fseStAppVersionService.updateFseStAppVersion(fseStAppVersion));
    }

    /**
     * 删除APP版本管理
     */
    @RequiresPermissions("fsepc:version:remove")
    @Log(title = "APP版本管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fseStAppVersionService.deleteFseStAppVersionByIds(ids));
    }




}
